home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / WASTE 1.2 / WASTE Tabs / WETabs.c < prev    next >
Text File  |  1996-06-18  |  2KB  |  88 lines

  1. /*
  2.  *    WETabs.c
  3.  *
  4.  *    Routines for installing and removing tab hooks
  5.  *
  6.  */
  7.  
  8. #include "WETabs.h"
  9.  
  10. /* prototypes for the hook routines defined in WETabHooks.c or WETabHooks32.c */
  11.  
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15.  
  16. extern pascal void _WETabDrawText(Ptr, long, Fixed, JustStyleCode, WEReference);
  17. extern pascal long _WETabPixelToChar(Ptr, long, Fixed,
  18.                     Fixed *, char *, JustStyleCode, Fixed, WEReference);
  19. extern pascal short _WETabCharToPixel(Ptr, long, Fixed, long, short,
  20.                     JustStyleCode, long, WEReference);
  21. extern pascal StyledLineBreakCode _WETabLineBreak(Ptr, long, long, long,
  22.                     Fixed *, long *, WEReference);
  23.  
  24. #ifdef __cplusplus
  25. }
  26. #endif
  27.  
  28. /* static UPP's */
  29. static WEDrawTextUPP        _weTabDrawTextProc = nil;
  30. static WEPixelToCharUPP        _weTabPixelToCharProc = nil;
  31. static WECharToPixelUPP        _weTabCharToPixelProc = nil;
  32. static WELineBreakUPP        _weTabLineBreakProc = nil;
  33.  
  34. pascal OSErr WEInstallTabHooks(WEReference we)
  35. {
  36.     OSErr err;
  37.  
  38.     /* if first time, create routine descriptors */
  39.     if (_weTabDrawTextProc == nil)
  40.     {
  41.         _weTabDrawTextProc = NewWEDrawTextProc(_WETabDrawText);
  42.         _weTabPixelToCharProc = NewWEPixelToCharProc(_WETabPixelToChar);
  43.         _weTabCharToPixelProc = NewWECharToPixelProc(_WETabCharToPixel);
  44.         _weTabLineBreakProc = NewWELineBreakProc(_WETabLineBreak);
  45.     }
  46.     
  47.     if ((err = WESetInfo( weDrawTextHook, &_weTabDrawTextProc, we )) != noErr)
  48.         goto cleanup;
  49.     if ((err = WESetInfo( wePixelToCharHook, &_weTabPixelToCharProc, we )) != noErr)
  50.         goto cleanup;
  51.     if ((err = WESetInfo( weCharToPixelHook, &_weTabCharToPixelProc, we )) != noErr)
  52.         goto cleanup;
  53.     if ((err = WESetInfo( weLineBreakHook, &_weTabLineBreakProc, we )) != noErr)
  54.         goto cleanup;
  55.  
  56. cleanup:
  57.     return err;
  58. }
  59.  
  60. pascal OSErr WERemoveTabHooks( WEReference we )
  61. {
  62.     UniversalProcPtr hook = nil;
  63.     OSErr err;
  64.     
  65.     if ((err = WESetInfo( weDrawTextHook, &hook, we )) != noErr)
  66.         goto cleanup;
  67.     if ((err = WESetInfo( wePixelToCharHook, &hook, we )) != noErr)
  68.         goto cleanup;    
  69.     if ((err = WESetInfo( weCharToPixelHook, &hook, we )) != noErr)
  70.         goto cleanup;
  71.     if ((err = WESetInfo( weLineBreakHook, &hook, we )) != noErr)
  72.         goto cleanup;
  73.  
  74. cleanup:
  75.     return err;
  76. }
  77.  
  78. pascal Boolean WEIsTabHooks( WEReference we )
  79. {
  80.     WEDrawTextUPP hook = nil;
  81.         
  82.     /* return true if our tab hooks are installed */
  83.     
  84.     return     ( _weTabDrawTextProc != nil ) &&
  85.             ( WEGetInfo( weDrawTextHook, &hook, we ) == noErr) &&
  86.             ( _weTabDrawTextProc == hook );
  87. }
  88.